/**
  ******************************************************************************
  * @file    ACAD_MEASURE.c
  * @author  Sherlock
  * @version V0.1
  * @date    10/12/2023
  * @brief   ACAD Handling
  ******************************************************************************
  * @copy
  *
  * <h2><center>&copy; COPYRIGHT 2010 Feirui</center></h2>
  */


/**
  * @brief  INCLUDE FILES.
  */
#ifndef	ACAD_MEASURE_GLOBALS
#define	ACAD_MEASURE_GLOBALS
#include <includes.h>
#include "acad_measure.h"
#include "acad_driver.h"
#include "acad_cfg.h"
#include "acad_core.h"
#include "communi_print.h"


static uint8_t ACRecdataHandling(AC_Receivedata_TypeDef  *ACdataStruction);


uint8_t ACAD_MeasureHandle(void)
{
	uint8_t os_err,Status=DEF_FALSE;
  	void *os_msg;
  	// float TempResult[ACADResultOrd_TOTNum];
    
	while(DEF_TRUE)
	{
		os_msg = OSQAccept(App_Q_ACAD, &os_err);  //无等待地从队列中取消息，直到消息为空，因为计算是实时的，不能因切换而漏消息
		if(os_msg == NULL)
			break;
		Status |= ACRecdataHandling((AC_Receivedata_TypeDef *)os_msg);
	}

	// if(Status)
	//     DoACADFilterAndUpdate(TempResult);
	
	return Status;
}


static void Cal_PhaseFilter_Value(int16_t *StartAddr, int16_t *DCAddr, uint8_t AddrInterval, uint16_t Number);
static void InitGlobalGensULastData(void);
static void InitGlobalGensVLastData(void);
static void InitGlobalGensWLastData(void);
// static void InitGlobalCurrULastData(void);
// static void InitGlobalCurrVLastData(void);
// static void InitGlobalCurrWLastData(void);
static void InitGlobalLoadULastData(void);
static void InitGlobalLoadVLastData(void);
static void InitGlobalLoadWLastData(void);
static void InitGlobalBuildVoltBEFLastData(void);


/* Handle AC dot Data */
static uint8_t ACRecdataHandling(AC_Receivedata_TypeDef *ACdataStruction)
{
#ifdef CalTime_Enable
 	GPIO_SetBits(GPIOC, GPIO_PIN_13); //测试PID输出时机
#endif

	/* Get Current Area  */
 	uint8_t AreaNumb=ACdataStruction->RawData;
 	uint8_t CurrNum=AreaNumb%ADCBufferAreaNum; //缓冲区1的当前块位置
	uint8_t BandFTNum=CurrNum%ADCBufferArea2Num; //缓冲区2的当前块位置

/******************************************************************************************************************************
 *                                                     滤波
 * ****************************************************************************************************************************/
	/* 被测电机去直流 */
	Cal_PhaseFilter_Value((int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensU,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensN,
							ADCDMA_ChannelNum, ADCSampleNumber);
	Cal_PhaseFilter_Value((int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensV,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensN,
							ADCDMA_ChannelNum, ADCSampleNumber);
	Cal_PhaseFilter_Value((int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensW,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensN,
							ADCDMA_ChannelNum, ADCSampleNumber);
	Cal_PhaseFilter_Value((int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_DroopA,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensN,
							ADCDMA_ChannelNum, ADCSampleNumber);
	Cal_PhaseFilter_Value((int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_DroopB,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensN,
							ADCDMA_ChannelNum, ADCSampleNumber);
	Cal_PhaseFilter_Value((int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_DroopC,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensN,
							ADCDMA_ChannelNum, ADCSampleNumber);

	/* 被测电机低通滤波 */
	ACAD_ChebyshevFilter(ChebyGensVoltV1LowpassXn,ChebyGensVoltV1LowpassYn,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensU,
		                (int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCPassZeroVoltGenU],ADCDMA_ChannelNum,ADCPassZero_ChannelNum,ADCSampleNumber);
	ACAD_ChebyshevFilter(ChebyGensVoltV2LowpassXn,ChebyGensVoltV2LowpassYn,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensV,
		                (int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCPassZeroVoltGenV],ADCDMA_ChannelNum,ADCPassZero_ChannelNum,ADCSampleNumber);
	ACAD_ChebyshevFilter(ChebyGensVoltV3LowpassXn,ChebyGensVoltV3LowpassYn,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensW,
		                (int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCPassZeroVoltGenW],ADCDMA_ChannelNum,ADCPassZero_ChannelNum,ADCSampleNumber);
	// ACAD_ChebyshevFilter(ChebyGensCurrV1LowpassXn,ChebyGensCurrV1LowpassYn,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_DroopA,
	// 	                (int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCZeroPassCurrU],ADCDMA_ChannelNum,ADCPassZero_ChannelNum,ADCSampleNumber);
	// ACAD_ChebyshevFilter(ChebyGensCurrV2LowpassXn,ChebyGensCurrV2LowpassYn,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_DroopB,
	// 	                (int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCZeroPassCurrV],ADCDMA_ChannelNum,ADCPassZero_ChannelNum,ADCSampleNumber);
	// ACAD_ChebyshevFilter(ChebyGensCurrV3LowpassXn,ChebyGensCurrV3LowpassYn,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_DroopC,
	// 	                (int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCZeroPassCurrW],ADCDMA_ChannelNum,ADCPassZero_ChannelNum,ADCSampleNumber);

	/* 负载电机去直流 */
	Cal_PhaseFilter_Value((int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_LoadU,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensN,
							ADCDMA_ChannelNum, ADCSampleNumber);
	Cal_PhaseFilter_Value((int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_LoadV,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensN,
							ADCDMA_ChannelNum, ADCSampleNumber);
	Cal_PhaseFilter_Value((int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_LoadW,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensN,
							ADCDMA_ChannelNum, ADCSampleNumber);

	/* 负载电机低通滤波 */
	ACAD_ChebyshevFilter(ChebyLoadVoltV1LowpassXn,ChebyLoadVoltV1LowpassYn,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_LoadU,
		                  (int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCPassZeroVoltLoadU],ADCDMA_ChannelNum,ADCPassZero_ChannelNum,ADCSampleNumber);
	ACAD_ChebyshevFilter(ChebyLoadVoltV2LowpassXn,ChebyLoadVoltV2LowpassYn,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_LoadV,
		                  (int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCPassZeroVoltLoadV],ADCDMA_ChannelNum,ADCPassZero_ChannelNum,ADCSampleNumber);
	ACAD_ChebyshevFilter(ChebyLoadVoltV3LowpassXn,ChebyLoadVoltV3LowpassYn,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_LoadW,
		                  (int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCPassZeroVoltLoadW],ADCDMA_ChannelNum,ADCPassZero_ChannelNum,ADCSampleNumber);
	
	/* 建磁电压去直流 */
	Cal_PhaseFilter_Value((int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_BuildVoltAFT,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensN,
							ADCDMA_ChannelNum, ADCSampleNumber);
	Cal_PhaseFilter_Value((int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_BuildVoltBEF,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GensN,
							ADCDMA_ChannelNum, ADCSampleNumber);
	/* 建磁电压过零点低通滤波 */
	ACAD_ChebyshevFilter(ChebyBuildVoltBEFLowpassXn,ChebyBuildVoltBEFLowpassYn,(int16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_BuildVoltBEF,
						(int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCBuildVoltBEF],ADCDMA_ChannelNum,ADCPassZero_ChannelNum,ADCSampleNumber);


/******************************************************************************************************************************
 *                                                过零点计算以及弱信号检测
 * ****************************************************************************************************************************/
	/* 被测电机 */
	uint8_t TempP0StaGensU=ScanVoltACZeroPassCoordi(ACTrace1stRecordFlag,(int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCPassZeroVoltGenU],ADCPassZero_ChannelNum,ADCSampleNumber,
		&PassPointMsgGensU,&GensUTraceRecordNum,AreaNumb,ACVoltTraceDCValLower,&GensUTraceRecordSta,&RecordGensUTraceMin,&RecordGensUTraceMax,&GensUTraceDCLimitUpper,&GensUTraceDCLimitLower);
	CheckInitACTraceRecord(TempP0StaGensU,&GensUTraceRecordNum,&GensUTraceRecordSta,&GensUTraceP0Counter,&GensUTraceLVStatus,&GensUTraceLVCounter,
												ACVoltTraceDCValLower,&RecordGensUTraceMin,&RecordGensUTraceMax,&GensUTraceDCLimitUpper,&GensUTraceDCLimitLower,InitGlobalGensULastData);
	
	uint8_t TempP0StaGensV=ScanVoltACZeroPassCoordi(ACTrace1stRecordFlag,(int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCPassZeroVoltGenV],ADCPassZero_ChannelNum,ADCSampleNumber,
		&PassPointMsgGensV,&GensVTraceRecordNum,AreaNumb,ACVoltTraceDCValLower,&GensVTraceRecordSta,&RecordGensVTraceMin,&RecordGensVTraceMax,&GensVTraceDCLimitUpper,&GensVTraceDCLimitLower);
	CheckInitACTraceRecord(TempP0StaGensV,&GensVTraceRecordNum,&GensVTraceRecordSta,&GensVTraceP0Counter,&GensVTraceLVStatus,&GensVTraceLVCounter,
												ACVoltTraceDCValLower,&RecordGensVTraceMin,&RecordGensVTraceMax,&GensVTraceDCLimitUpper,&GensVTraceDCLimitLower,InitGlobalGensVLastData);
	
	uint8_t TempP0StaGensW=ScanVoltACZeroPassCoordi(ACTrace1stRecordFlag,(int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCPassZeroVoltGenW],ADCPassZero_ChannelNum,ADCSampleNumber,
		&PassPointMsgGensW,&GensWTraceRecordNum,AreaNumb,ACVoltTraceDCValLower,&GensWTraceRecordSta,&RecordGensWTraceMin,&RecordGensWTraceMax,&GensWTraceDCLimitUpper,&GensWTraceDCLimitLower);
	CheckInitACTraceRecord(TempP0StaGensW,&GensWTraceRecordNum,&GensWTraceRecordSta,&GensWTraceP0Counter,&GensWTraceLVStatus,&GensWTraceLVCounter,
												ACVoltTraceDCValLower,&RecordGensWTraceMin,&RecordGensWTraceMax,&GensWTraceDCLimitUpper,&GensWTraceDCLimitLower,InitGlobalGensWLastData);
	
	/* 被测电机电流 */
	// uint8_t TempP0StaCurrU=ScanVoltACZeroPassCoordi(ACTrace1stRecordFlag,(int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCZeroPassCurrU],ADCPassZero_ChannelNum,ADCSampleNumber,
	// 	&PassPointMsgCurrU,&CurrUTraceRecordNum,AreaNumb,ACVoltTraceDCValLower,&CurrUTraceRecordSta,&RecordCurrUTraceMin,&RecordCurrUTraceMax,&CurrUTraceDCLimitUpper,&CurrUTraceDCLimitLower);
	// CheckInitACTraceRecord(TempP0StaCurrU,&CurrUTraceRecordNum,&CurrUTraceRecordSta,&CurrUTraceP0Counter,&CurrUTraceLVStatus,&CurrUTraceLVCounter,
	// 											ACVoltTraceDCValLower,&RecordCurrUTraceMin,&RecordCurrUTraceMax,&CurrUTraceDCLimitUpper,&CurrUTraceDCLimitLower,InitGlobalCurrULastData);

	// uint8_t TempP0StaCurrV=ScanVoltACZeroPassCoordi(ACTrace1stRecordFlag,(int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCZeroPassCurrV],ADCPassZero_ChannelNum,ADCSampleNumber,
	// 	&PassPointMsgCurrV,&CurrVTraceRecordNum,AreaNumb,ACVoltTraceDCValLower,&CurrVTraceRecordSta,&RecordCurrVTraceMin,&RecordCurrVTraceMax,&CurrVTraceDCLimitUpper,&CurrVTraceDCLimitLower);
	// CheckInitACTraceRecord(TempP0StaCurrV,&CurrVTraceRecordNum,&CurrVTraceRecordSta,&CurrVTraceP0Counter,&CurrVTraceLVStatus,&CurrVTraceLVCounter,
	// 											ACVoltTraceDCValLower,&RecordCurrVTraceMin,&RecordCurrVTraceMax,&CurrVTraceDCLimitUpper,&CurrVTraceDCLimitLower,InitGlobalCurrVLastData);
	
	// uint8_t TempP0StaCurrW=ScanVoltACZeroPassCoordi(ACTrace1stRecordFlag,(int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCZeroPassCurrW],ADCPassZero_ChannelNum,ADCSampleNumber,
	// 	&PassPointMsgCurrW,&CurrWTraceRecordNum,AreaNumb,ACVoltTraceDCValLower,&CurrWTraceRecordSta,&RecordCurrWTraceMin,&RecordCurrWTraceMax,&CurrWTraceDCLimitUpper,&CurrWTraceDCLimitLower);
	// CheckInitACTraceRecord(TempP0StaCurrW,&CurrWTraceRecordNum,&CurrWTraceRecordSta,&CurrWTraceP0Counter,&CurrWTraceLVStatus,&CurrWTraceLVCounter,
	// 											ACVoltTraceDCValLower,&RecordCurrWTraceMin,&RecordCurrWTraceMax,&CurrWTraceDCLimitUpper,&CurrWTraceDCLimitLower,InitGlobalCurrWLastData);
	
	/* 负载电机 */
	uint8_t TempP0StaLoadU=ScanVoltACZeroPassCoordi(ACTrace1stRecordFlag,(int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCPassZeroVoltLoadU],ADCPassZero_ChannelNum,ADCSampleNumber,
		&PassPointMsgLoadU,&LoadUTraceRecordNum,AreaNumb,ACVoltTraceDCValLower,&LoadUTraceRecordSta,&RecordLoadUTraceMin,&RecordLoadUTraceMax,&LoadUTraceDCLimitUpper,&LoadUTraceDCLimitLower);
	CheckInitACTraceRecord(TempP0StaLoadU,&LoadUTraceRecordNum,&LoadUTraceRecordSta,&LoadUTraceP0Counter,&LoadUTraceLVStatus,&LoadUTraceLVCounter,
												ACVoltTraceDCValLower,&RecordLoadUTraceMin,&RecordLoadUTraceMax,&LoadUTraceDCLimitUpper,&LoadUTraceDCLimitLower,InitGlobalLoadULastData);
	
	uint8_t TempP0StaLoadV=ScanVoltACZeroPassCoordi(ACTrace1stRecordFlag,(int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCPassZeroVoltLoadV],ADCPassZero_ChannelNum,ADCSampleNumber,
		&PassPointMsgLoadV,&LoadVTraceRecordNum,AreaNumb,ACVoltTraceDCValLower,&LoadVTraceRecordSta,&RecordLoadVTraceMin,&RecordLoadVTraceMax,&LoadVTraceDCLimitUpper,&LoadVTraceDCLimitLower);
	CheckInitACTraceRecord(TempP0StaLoadV,&LoadVTraceRecordNum,&LoadVTraceRecordSta,&LoadVTraceP0Counter,&LoadVTraceLVStatus,&LoadVTraceLVCounter,
												ACVoltTraceDCValLower,&RecordLoadVTraceMin,&RecordLoadVTraceMax,&LoadVTraceDCLimitUpper,&LoadVTraceDCLimitLower,InitGlobalLoadVLastData);

	uint8_t TempP0StaLoadW=ScanVoltACZeroPassCoordi(ACTrace1stRecordFlag,(int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCPassZeroVoltLoadW],ADCPassZero_ChannelNum,ADCSampleNumber,
		&PassPointMsgLoadW,&LoadWTraceRecordNum,AreaNumb,ACVoltTraceDCValLower,&LoadWTraceRecordSta,&RecordLoadWTraceMin,&RecordLoadWTraceMax,&LoadWTraceDCLimitUpper,&LoadWTraceDCLimitLower);
	CheckInitACTraceRecord(TempP0StaLoadW,&LoadWTraceRecordNum,&LoadWTraceRecordSta,&LoadWTraceP0Counter,&LoadWTraceLVStatus,&LoadWTraceLVCounter,
												ACVoltTraceDCValLower,&RecordLoadWTraceMin,&RecordLoadWTraceMax,&LoadWTraceDCLimitUpper,&LoadWTraceDCLimitLower,InitGlobalLoadWLastData);
	
	/* 建磁电压 */
	uint8_t TempP0StaBuildVoltBEF=ScanVoltACZeroPassCoordi(ACTrace1stRecordFlag,(int16_t *)&ADCPassZeroLowPassTab[BandFTNum*ADCSampleNumber*ADCPassZero_ChannelNum+ADCBuildVoltBEF],ADCPassZero_ChannelNum,ADCSampleNumber,
		&PassPointMsgBuildVoltBEF,&BuildVoltBEFTraceRecordNum,AreaNumb,ACVoltTraceDCValLower,&BuildVoltBEFTraceRecordSta,&RecordBuildVoltBEFTraceMin,&RecordBuildVoltBEFTraceMax,&BuildVoltBEFTraceDCLimitUpper,&BuildVoltBEFTraceDCLimitLower);
	CheckInitACTraceRecord(TempP0StaBuildVoltBEF,&BuildVoltBEFTraceRecordNum,&BuildVoltBEFTraceRecordSta,&BuildVoltBEFTraceP0Counter,&BuildVoltBEFTraceLVStatus,&BuildVoltBEFTraceLVCounter,
												ACVoltTraceDCValLower,&RecordBuildVoltBEFTraceMin,&RecordBuildVoltBEFTraceMax,&BuildVoltBEFTraceDCLimitUpper,&BuildVoltBEFTraceDCLimitLower,InitGlobalBuildVoltBEFLastData);


/****************************************************************************************************************************
 *                                                    计算电压数据
 ****************************************************************************************************************************/
	/***********计算被测电机的频率和电压 start***********/
	float TempFreGensU=0,TempFreGensV=0,TempFreGensW=0;
	int16_t *GensUPoint, *GensVPoint, *GensWPoint;
	float GensURemainTime, GensUCurrPointTime, GensUCycleTime, GensVRemainTime, GensVCurrPointTime, GensVCycleTime, GensWRemainTime, GensWCurrPointTime, GensWCycleTime;
	uint16_t GensUDotNumber, GensVDotNumber, GensWDotNumber;
	float TempVoltGensU=0,TempVoltGensV=0,TempVoltGensW=0,TempVoltGensUV=0,TempVoltGensVW=0,TempVoltGensWU=0;
	float GensUVPhaseOrder=0, GensUWPhaseOrder=0;

	/* U相电压 */
	TempFreGensU=CalVoltFreFromTraceRecord(&PassPointMsgGensU,GensUTraceRecordNum,GensUGlobalVoltFre);
	if(TempFreGensU<ACWaveFormFreMin)
		TempFreGensU=0;
	else
		GensUGlobalVoltFre=TempFreGensU; //更新全局频率

	if(TempFreGensU>=ACVoltSTRFreqMin)	//计算U相的相电压值
	{
		GensUPoint    =GetACCycleViewMSG(&PassPointMsgGensU,(int16_t *)ACBufferArea1Address[CurrNum]+(ADCSampleNumber-1)*ADCDMA_ChannelNum+ADCDMAChannelOrd_GensU,&GensUDotNumber,&GensUCycleTime,&GensURemainTime,&GensUCurrPointTime);
		TempVoltGensU =CalADCVoltVirtualPhaseValue(GensUPoint,ADCDMA_ChannelNum,GensUDotNumber,GensUCycleTime,GensURemainTime,GensUCurrPointTime);
		TempVoltGensU*=DefaultValHWCalibGenVoltP1;
		if(TempVoltGensU < DetectMinVoltLimit)  //最低电压检测
		{
			TempVoltGensU=0;
			TempFreGensU=0;
			GensUGlobalVoltFre=0;
		}
	}
	else
		TempVoltGensU=0;
  
	/* V相电压 */
	TempFreGensV=CalVoltFreFromTraceRecord(&PassPointMsgGensV,GensVTraceRecordNum,GensVGlobalVoltFre);
	if(TempFreGensV<ACWaveFormFreMin)
		TempFreGensV=0;
	else
		GensVGlobalVoltFre=TempFreGensV; //更新全局频率

	if(TempFreGensV>=ACVoltSTRFreqMin)	//计算U相的相电压值
	{
		GensVPoint    =GetACCycleViewMSG(&PassPointMsgGensV,(int16_t *)ACBufferArea1Address[CurrNum]+(ADCSampleNumber-1)*ADCDMA_ChannelNum+ADCDMAChannelOrd_GensV,&GensVDotNumber,&GensVCycleTime,&GensVRemainTime,&GensVCurrPointTime);
		TempVoltGensV =CalADCVoltVirtualPhaseValue(GensVPoint,ADCDMA_ChannelNum,GensVDotNumber,GensVCycleTime,GensVRemainTime,GensVCurrPointTime);
		TempVoltGensV*=DefaultValHWCalibGenVoltP2;
		if(TempVoltGensV < DetectMinVoltLimit)
		{
			TempVoltGensV=0;
			TempFreGensV=0;
			GensVGlobalVoltFre=0;
		}
	}
	else
		TempVoltGensV=0;

	/* W相电压 */
	TempFreGensW=CalVoltFreFromTraceRecord(&PassPointMsgGensW,GensWTraceRecordNum,GensWGlobalVoltFre);
	if(TempFreGensW<ACWaveFormFreMin)
		TempFreGensW=0;
	else
		GensWGlobalVoltFre=TempFreGensW; //更新全局频率

	if(TempFreGensW>=ACVoltSTRFreqMin)	//计算U相的相电压值
	{
		GensWPoint    =GetACCycleViewMSG(&PassPointMsgGensW,(int16_t *)ACBufferArea1Address[CurrNum]+(ADCSampleNumber-1)*ADCDMA_ChannelNum+ADCDMAChannelOrd_GensW,&GensWDotNumber,&GensWCycleTime,&GensWRemainTime,&GensWCurrPointTime);
		TempVoltGensW =CalADCVoltVirtualPhaseValue(GensWPoint,ADCDMA_ChannelNum,GensWDotNumber,GensWCycleTime,GensWRemainTime,GensWCurrPointTime);
		TempVoltGensW*=DefaultValHWCalibGenVoltP3;
		if(TempVoltGensW < DetectMinVoltLimit)
		{
			TempVoltGensW=0;
			TempFreGensW=0;
			GensWGlobalVoltFre=0;
		}
	}
	else
		TempVoltGensW=0;

  	/* UV线电压 */
	if(TempFreGensU>=ACVoltSTRFreqMin)
	{
		TempVoltGensUV=CalADCVirtualLineValue(GensUPoint,GensUPoint+ADCDMAChannelOrd_GensV-ADCDMAChannelOrd_GensU,ADCDMA_ChannelNum,GensUDotNumber,GensUCycleTime,GensURemainTime,GensUCurrPointTime,DefaultValHWCalibGenVoltP1,DefaultValHWCalibGenVoltP2);
		TempVoltGensUV*=DefaultValHWCalibGenVoltL12;
		GensUVPhaseOrder = CalPhaseFromTraceRecord(&PassPointMsgGensU, &PassPointMsgGensV);
	}
	else
		TempVoltGensUV=0;

  	/* VW线电压 */
	if(TempFreGensV>=ACVoltSTRFreqMin)
	{
		TempVoltGensVW=CalADCVirtualLineValue(GensVPoint,GensVPoint+ADCDMAChannelOrd_GensW-ADCDMAChannelOrd_GensV,ADCDMA_ChannelNum,GensVDotNumber,GensVCycleTime,GensVRemainTime,GensVCurrPointTime,DefaultValHWCalibGenVoltP2,DefaultValHWCalibGenVoltP3);
		TempVoltGensVW*=DefaultValHWCalibGenVoltL23;
		GensUWPhaseOrder = CalPhaseFromTraceRecord(&PassPointMsgGensU, &PassPointMsgGensW);
	}
	else
		TempVoltGensUV=0;

  	/* WU线电压 */
	if(TempFreGensW>=ACVoltSTRFreqMin)
	{
		TempVoltGensWU=CalADCVirtualLineValue(GensWPoint,GensWPoint+ADCDMAChannelOrd_GensU-ADCDMAChannelOrd_GensW,ADCDMA_ChannelNum,GensWDotNumber,GensWCycleTime,GensWRemainTime,GensWCurrPointTime,DefaultValHWCalibGenVoltP3,DefaultValHWCalibGenVoltP1);
		TempVoltGensWU*=DefaultValHWCalibGenVoltL31;
	}
	else
		TempVoltGensUV=0;
	/***********计算被测电机的频率和电压 end***********/

	/***********计算负载电机的频率和电压 start***********/
	float TempFreLoadU=0,TempFreLoadV=0,TempFreLoadW=0;
	int16_t *LoadUPoint, *LoadVPoint, *LoadWPoint;
	float LoadURemainTime, LoadUCurrPointTime, LoadUCycleTime, LoadVRemainTime, LoadVCurrPointTime, LoadVCycleTime, LoadWRemainTime, LoadWCurrPointTime, LoadWCycleTime;
	uint16_t LoadUDotNumber, LoadVDotNumber, LoadWDotNumber;
	float TempVoltLoadU=0,TempVoltLoadV=0,TempVoltLoadW=0,TempVoltLoadUV=0,TempVoltLoadVW=0,TempVoltLoadWU=0;
	float LoadUVPhaseOrder=0, LoadUWPhaseOrder=0;

	/* U相电压 */
	TempFreLoadU=CalVoltFreFromTraceRecord(&PassPointMsgLoadU,LoadUTraceRecordNum,LoadUGlobalVoltFre);
	if(TempFreLoadU<ACWaveFormFreMin)
		TempFreLoadU=0;
	else
		LoadUGlobalVoltFre=TempFreLoadU; //更新全局频率

	if(TempFreLoadU>=ACVoltSTRFreqMin)	//计算U相的相电压值
	{
		LoadUPoint    =GetACCycleViewMSG(&PassPointMsgLoadU,(int16_t *)ACBufferArea1Address[CurrNum]+(ADCSampleNumber-1)*ADCDMA_ChannelNum+ADCDMAChannelOrd_LoadU,&LoadUDotNumber,&LoadUCycleTime,&LoadURemainTime,&LoadUCurrPointTime);
		TempVoltLoadU =CalADCVoltVirtualPhaseValue(LoadUPoint,ADCDMA_ChannelNum,LoadUDotNumber,LoadUCycleTime,LoadURemainTime,LoadUCurrPointTime);
		TempVoltLoadU*=DefaultValHWCalibGenVoltP1;
		if(TempVoltLoadU < DetectMinVoltLimit)   //最低电压检测
		{
			TempVoltLoadU=0;
			TempFreLoadU=0;
			LoadUGlobalVoltFre=0;
		}
	}
	else
		TempVoltLoadU=0;
  
	/* V相电压 */
	TempFreLoadV=CalVoltFreFromTraceRecord(&PassPointMsgLoadV,LoadVTraceRecordNum,LoadVGlobalVoltFre);
	if(TempFreLoadV<ACWaveFormFreMin)
		TempFreLoadV=0;
	else
		LoadVGlobalVoltFre=TempFreLoadV; //更新全局频率

	if(TempFreLoadV>=ACVoltSTRFreqMin)	//计算U相的相电压值
	{
		LoadVPoint    =GetACCycleViewMSG(&PassPointMsgLoadV,(int16_t *)ACBufferArea1Address[CurrNum]+(ADCSampleNumber-1)*ADCDMA_ChannelNum+ADCDMAChannelOrd_LoadV,&LoadVDotNumber,&LoadVCycleTime,&LoadVRemainTime,&LoadVCurrPointTime);
		TempVoltLoadV =CalADCVoltVirtualPhaseValue(LoadVPoint,ADCDMA_ChannelNum,LoadVDotNumber,LoadVCycleTime,LoadVRemainTime,LoadVCurrPointTime);
		TempVoltLoadV*=DefaultValHWCalibGenVoltP2;
		if(TempVoltLoadV < DetectMinVoltLimit)   //最低电压检测
		{
			TempVoltLoadV=0;
			TempFreLoadV=0;
			LoadVGlobalVoltFre=0;
		}
	}
	else
		TempVoltLoadV=0;

	/* W相电压 */
	TempFreLoadW=CalVoltFreFromTraceRecord(&PassPointMsgLoadW,LoadWTraceRecordNum,LoadWGlobalVoltFre);
	if(TempFreLoadW<ACWaveFormFreMin)
		TempFreLoadW=0;
	else
		LoadWGlobalVoltFre=TempFreLoadW; //更新全局频率

	if(TempFreLoadW>=ACVoltSTRFreqMin)	//计算U相的相电压值
	{
		LoadWPoint    =GetACCycleViewMSG(&PassPointMsgLoadW,(int16_t *)ACBufferArea1Address[CurrNum]+(ADCSampleNumber-1)*ADCDMA_ChannelNum+ADCDMAChannelOrd_LoadW,&LoadWDotNumber,&LoadWCycleTime,&LoadWRemainTime,&LoadWCurrPointTime);
		TempVoltLoadW =CalADCVoltVirtualPhaseValue(LoadWPoint,ADCDMA_ChannelNum,LoadWDotNumber,LoadWCycleTime,LoadWRemainTime,LoadWCurrPointTime);
		TempVoltLoadW*=DefaultValHWCalibGenVoltP3;
		if(TempVoltLoadW < DetectMinVoltLimit)   //最低电压检测
		{
			TempVoltLoadW=0;
			TempFreLoadW=0;
			LoadWGlobalVoltFre=0;
		}
	}
	else
		TempVoltLoadW=0;

	/* UV线电压 */
	if(TempFreLoadU>=ACVoltSTRFreqMin)
	{
		TempVoltLoadUV=CalADCVirtualLineValue(LoadUPoint,LoadUPoint+ADCDMAChannelOrd_LoadV-ADCDMAChannelOrd_LoadU,ADCDMA_ChannelNum,LoadUDotNumber,LoadUCycleTime,LoadURemainTime,LoadUCurrPointTime,DefaultValHWCalibGenVoltP1,DefaultValHWCalibGenVoltP2);
		TempVoltLoadUV*=DefaultValHWCalibGenVoltL12;

		LoadUVPhaseOrder = CalPhaseFromTraceRecord(&PassPointMsgLoadU, &PassPointMsgLoadV);  //相位检测
	}
	else
		TempVoltLoadUV=0;

	/* VW线电压 */
	if(TempFreLoadV>=ACVoltSTRFreqMin)
	{
		TempVoltLoadVW=CalADCVirtualLineValue(LoadVPoint,LoadVPoint+ADCDMAChannelOrd_LoadW-ADCDMAChannelOrd_LoadV,ADCDMA_ChannelNum,LoadVDotNumber,LoadVCycleTime,LoadVRemainTime,LoadVCurrPointTime,DefaultValHWCalibGenVoltP2,DefaultValHWCalibGenVoltP3);
		TempVoltLoadVW*=DefaultValHWCalibGenVoltL23;

		LoadUWPhaseOrder = CalPhaseFromTraceRecord(&PassPointMsgLoadU, &PassPointMsgLoadW);
	}
	else
		TempVoltLoadUV=0;

	/* WU线电压 */
	if(TempFreLoadW>=ACVoltSTRFreqMin)
	{
		TempVoltLoadWU=CalADCVirtualLineValue(LoadWPoint,LoadWPoint+ADCDMAChannelOrd_LoadU-ADCDMAChannelOrd_LoadW,ADCDMA_ChannelNum,LoadWDotNumber,LoadWCycleTime,LoadWRemainTime,LoadWCurrPointTime,DefaultValHWCalibGenVoltP3,DefaultValHWCalibGenVoltP1);
		TempVoltLoadWU*=DefaultValHWCalibGenVoltL31;
	}
	else
		TempVoltLoadUV=0;
	/***********计算负载电机的频率和电压 end***********/

	/***********计算两台电机的同步信息 start***********/
	float TempSynchronousPhaseU, TempSynchronousPhaseV, TempSynchronousPhaseW;  //相位差
	float TempSynchronousVoltU, TempSynchronousVoltV, TempSynchronousVoltW;     //电压模差
	TempSynchronousPhaseU = CalPhaseFromTraceRecord(&PassPointMsgGensU, &PassPointMsgLoadU);
	TempSynchronousPhaseV = CalPhaseFromTraceRecord(&PassPointMsgGensV, &PassPointMsgLoadV);
	TempSynchronousPhaseW = CalPhaseFromTraceRecord(&PassPointMsgGensW, &PassPointMsgLoadW);
	TempSynchronousVoltU = TempVoltGensU - TempVoltLoadU;
	TempSynchronousVoltV = TempVoltGensV - TempVoltLoadV;
	TempSynchronousVoltW = TempVoltGensW - TempVoltLoadW;
	float tempSyncErrU = 0, tempSyncErrV = 0, tempSyncErrW = 0;
	if(testBenchWorkMode == BenchWorkMode_SyncAuto)
	{
		tempSyncErrU = CalGovSyncErr(&SyncErrModeLevelU, &SyncErrU1stSta, &SyncLastErrU, &PassPointMsgGensU, &PassPointMsgLoadU);
		// tempSyncErrV = CalGovSyncErr(&SyncErrModeLevelV, &SyncErrV1stSta, &SyncLastErrV, &PassPointMsgGensV, &PassPointMsgLoadV);
		// tempSyncErrW = CalGovSyncErr(&SyncErrModeLevelW, &SyncErrW1stSta, &SyncLastErrW, &PassPointMsgGensW, &PassPointMsgLoadW);
	}
	/***********计算两台电机的同步信息 end***********/


/****************************************************************************************************************************
 *                                                   电流数据计算
 ****************************************************************************************************************************/
	float TempCurrGensU=0, TempCurrGensV=0, TempCurrGensW=0;
	int16_t *GenIUPoint, *GenIVPoint, *GenIWPoint;

	if(TempFreGensU>=ACCurrSTRFreqMin)
	{
		/* 计算U相电流，没必要计算电流的频率，直接带入VW相关数据即可 */
		GenIUPoint = (int16_t *)ACBufferArea1Address[CurrNum] + (ADCSampleNumber-1)*ADCDMA_ChannelNum + ADCDMAChannelOrd_DroopA - GensUDotNumber * ADCDMA_ChannelNum; //获取最近的周期起始点
		if (GenIUPoint < (int16_t *)ACBufferArea1Address[0]) //如果周期起始点超出缓冲区起始点，则加上整个缓冲区长度（环形缓冲）
		{
			GenIUPoint = GenIUPoint + ADC2bBufferNum;
		}
		TempCurrGensU =CalADCVoltVirtualPhaseValue(GenIUPoint,ADCDMA_ChannelNum,GensUDotNumber,GensUCycleTime,GensURemainTime,GensUCurrPointTime);
		TempCurrGensU*=DefaultValHWCalibGenCurrL1;
		if(TempCurrGensU < DetectMinCurrLimit)
		{
			TempCurrGensU=0;
		}
	}
	else
	{
		TempCurrGensU=0;
	}

	if(TempFreGensV>=ACCurrSTRFreqMin)
	{
		/* 计算V相电流 */
		GenIVPoint = (int16_t *)ACBufferArea1Address[CurrNum] + (ADCSampleNumber-1)*ADCDMA_ChannelNum + ADCDMAChannelOrd_DroopB - GensVDotNumber * ADCDMA_ChannelNum; //获取最近的周期起始点
		if (GenIVPoint < (int16_t *)ACBufferArea1Address[0]) //如果周期起始点超出缓冲区起始点，则加上整个缓冲区长度（环形缓冲）
		{
			GenIVPoint = GenIVPoint + ADC2bBufferNum;
		}
		TempCurrGensV =CalADCVoltVirtualPhaseValue(GenIVPoint,ADCDMA_ChannelNum,GensVDotNumber,GensVCycleTime,GensVRemainTime,GensVCurrPointTime);
		TempCurrGensV*=DefaultValHWCalibGenCurrL2;
		if(TempCurrGensV < DetectMinCurrLimit)
		{
			TempCurrGensV=0;
		}
	}
	else
	{
		TempCurrGensV=0;
	}

	if(TempFreGensW>=ACCurrSTRFreqMin)
	{
		/* 计算W相电流 */
		GenIWPoint = (int16_t *)ACBufferArea1Address[CurrNum] + (ADCSampleNumber-1)*ADCDMA_ChannelNum + ADCDMAChannelOrd_DroopC - GensWDotNumber * ADCDMA_ChannelNum; //获取最近的周期起始点
		if (GenIWPoint < (int16_t *)ACBufferArea1Address[0]) //如果周期起始点超出缓冲区起始点，则加上整个缓冲区长度（环形缓冲）
		{
			GenIWPoint = GenIWPoint + ADC2bBufferNum;
		}
		TempCurrGensW =CalADCVoltVirtualPhaseValue(GenIWPoint,ADCDMA_ChannelNum,GensWDotNumber,GensWCycleTime,GensWRemainTime,GensWCurrPointTime);
		TempCurrGensW*=DefaultValHWCalibGenCurrL3;
		if(TempCurrGensW < DetectMinCurrLimit)
		{
			TempCurrGensW=0;
		}
	}
	else
	{
		TempCurrGensW=0;
	}


/****************************************************************************************************************************
 *                                                   功率数据计算
 ****************************************************************************************************************************/
	float TempPowerPGensU=0,TempPowerQGensU=0,TempPowerPGensV=0,TempPowerQGensV=0,TempPowerPGensW=0,TempPowerQGensW=0,TempPowerSGensU=0,TempPowerSGensV=0,TempPowerSGensW=0;
	float TempPFL1=0,TempPFL2=0,TempPFL3=0;
	// float TempPhaseUI1=0,TempPhaseUI2=0,TempPhaseUI3=0;

	if(TempFreGensU>=ACPowrSTRFreqMin && TempCurrGensU>0)
	{
		TempPowerPGensU=CalADCPowerValue(GensUPoint,ADCDMAChannelOrd_DroopA-ADCDMAChannelOrd_GensU,ADCDMA_ChannelNum,GensUDotNumber,GensUCycleTime,GensURemainTime,GensUCurrPointTime);
		TempPowerPGensU*=DefaultValHWCalibGenVoltP1*DefaultValHWCalibGenCurrL1*DefaultValHWCalibGenKWL1;

		TempPowerQGensU=CalADCPowerQValue(GensUPoint,ADCDMAChannelOrd_DroopA-ADCDMAChannelOrd_GensU,ADCDMA_ChannelNum,GensUDotNumber,GensUCycleTime,GensURemainTime,GensUCurrPointTime);
		TempPowerQGensU*=DefaultValHWCalibGenVoltP1*DefaultValHWCalibGenCurrL1*DefaultValHWCalibGenKVArL1;

		if(arm_sqrt_f32(TempPowerPGensU*TempPowerPGensU+TempPowerQGensU*TempPowerQGensU, &TempPowerSGensU)<0)  //均方根值
			SYS_DebugERROR;

		TempPFL1 = TempPowerSGensU != 0 ? TempPowerPGensU/TempPowerSGensU : 0;
		// TempPhaseUI1=CalPhaseFromPowerFactor(TempPowerPGensU, TempPowerQGensU, TempPowerSGensU);
	}
	else
	{
		TempPowerPGensU=0;
		TempPowerQGensU=0;
		TempPowerSGensU=0;
		// TempPhaseUI1=0;
		TempPFL1=0;
	}

	if(TempFreGensV>=ACPowrSTRFreqMin && TempCurrGensV>0)
	{
		TempPowerPGensV=CalADCPowerValue(GensVPoint,ADCDMAChannelOrd_DroopB-ADCDMAChannelOrd_GensV,ADCDMA_ChannelNum,GensVDotNumber,GensVCycleTime,GensVRemainTime,GensVCurrPointTime);
		TempPowerPGensV*=DefaultValHWCalibGenVoltP2*DefaultValHWCalibGenCurrL2*DefaultValHWCalibGenKWL2;

		TempPowerQGensV=CalADCPowerQValue(GensVPoint,ADCDMAChannelOrd_DroopB-ADCDMAChannelOrd_GensV,ADCDMA_ChannelNum,GensVDotNumber,GensVCycleTime,GensVRemainTime,GensVCurrPointTime);
		TempPowerQGensV*=DefaultValHWCalibGenVoltP2*DefaultValHWCalibGenCurrL2*DefaultValHWCalibGenKVArL2;
	
		if(arm_sqrt_f32(TempPowerPGensV*TempPowerPGensV+TempPowerQGensV*TempPowerQGensV, &TempPowerSGensV)<0)  //均方根值
			SYS_DebugERROR;

		TempPFL2 = TempPowerSGensV != 0 ? TempPowerPGensV/TempPowerSGensV : 0;
		// TempPhaseUI2=CalPhaseFromPowerFactor(TempPowerPGensV, TempPowerQGensV, TempPowerSGensV);
	}
	else
	{
		TempPowerPGensV=0;
		TempPowerQGensV=0;
		TempPowerSGensV=0;
		// TempPhaseUI2=0;
		TempPFL2=0;
	}

	if(TempFreGensW>=ACPowrSTRFreqMin && TempCurrGensW>0)
	{
		/* 计算最近一周期和半周期数据，不一定需要过零点 */
		TempPowerPGensW=CalADCPowerValue(GensWPoint,ADCDMAChannelOrd_DroopC-ADCDMAChannelOrd_GensW,ADCDMA_ChannelNum,GensWDotNumber,GensWCycleTime,GensWRemainTime,GensWCurrPointTime);
		TempPowerPGensW*=DefaultValHWCalibGenVoltP3*DefaultValHWCalibGenCurrL3*DefaultValHWCalibGenKWL3;

		TempPowerQGensW=CalADCPowerQValue(GensWPoint,ADCDMAChannelOrd_DroopC-ADCDMAChannelOrd_GensW,ADCDMA_ChannelNum,GensWDotNumber,GensWCycleTime,GensWRemainTime,GensWCurrPointTime);
		TempPowerQGensW*=DefaultValHWCalibGenVoltP3*DefaultValHWCalibGenCurrL3*DefaultValHWCalibGenKVArL3;

		if(arm_sqrt_f32(TempPowerPGensW*TempPowerPGensW+TempPowerQGensW*TempPowerQGensW, &TempPowerSGensW)<0)  //均方根值
			SYS_DebugERROR;
		
		TempPFL3 = TempPowerSGensW != 0 ? TempPowerPGensW/TempPowerSGensW : 0;
		// TempPhaseUI3=CalPhaseFromPowerFactor(TempPowerPGensW, TempPowerQGensW, TempPowerSGensW);
	}
	else
	{
		TempPowerPGensW=0;
		TempPowerQGensW=0;
		TempPowerSGensW=0;
		// TempPhaseUI3=0;
		TempPFL3=0;
	}


/****************************************************************************************************************************
 *                                                    励磁电压电流
 ****************************************************************************************************************************/
	float tempGenExciteVolt = Cal_1OrdLowPassFilter(&ADCLastValue_GenExciteVolt,(uint16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GenEXCV, ADCDMA_ChannelNum, ADCSampleNumber, LowPassFilterValue_GenExciteVolt);
	float tempGenExciteCurr = Cal_1OrdLowPassFilter(&ADCLastValue_GenExciteCurr,(uint16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_GenEXCI, ADCDMA_ChannelNum, ADCSampleNumber, LowPassFilterValue_GenExciteCurr);
	float tempLoadExciteVolt = Cal_1OrdLowPassFilter(&ADCLastValue_LoadExciteVolt,(uint16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_LoadEXCV, ADCDMA_ChannelNum, ADCSampleNumber, LowPassFilterValue_GenExciteVolt);
	float tempLoadExciteCurr = Cal_1OrdLowPassFilter(&ADCLastValue_LoadExciteCurr,(uint16_t *)ACBufferArea1Address[CurrNum]+ADCDMAChannelOrd_LoadEXCI, ADCDMA_ChannelNum, ADCSampleNumber, LowPassFilterValue_GenExciteCurr);
	tempGenExciteVolt *= DefaultValHWCalibGenExciteVolt;
	tempGenExciteCurr *= DefaultValHWCalibGenExciteCurr;
	tempLoadExciteVolt *= DefaultValHWCalibGenExciteVolt;
	tempLoadExciteCurr *= DefaultValHWCalibGenExciteCurr;


/****************************************************************************************************************************
 *                                                    建磁电压
 ****************************************************************************************************************************/
	float TempFreBuildVoltBEF=0;
	int16_t *BuildVoltBEFPoint;
	float BuildVoltBEFRemainTime, BuildVoltBEFCurrPointTime, BuildVoltBEFCycleTime;
	uint16_t BuildVoltBEFDotNumber;
	float TempVoltBuildVoltBEF=0, TempVoltBuildVoltAFT=0;

	TempFreBuildVoltBEF=CalVoltFreFromTraceRecord(&PassPointMsgBuildVoltBEF,BuildVoltBEFTraceRecordNum,BuildVoltBEFGlobalVoltFre);
	if(TempFreBuildVoltBEF<ACWaveFormFreMin)
		TempFreBuildVoltBEF=0;
	else
		BuildVoltBEFGlobalVoltFre=TempFreBuildVoltBEF; //更新全局频率

	if(TempFreBuildVoltBEF>=ACVoltSTRFreqMin)	//计算U相的相电压值
	{
		BuildVoltBEFPoint    =GetACCycleViewMSG(&PassPointMsgBuildVoltBEF,(int16_t *)ACBufferArea1Address[CurrNum]+(ADCSampleNumber-1)*ADCDMA_ChannelNum+ADCDMAChannelOrd_BuildVoltBEF,&BuildVoltBEFDotNumber,&BuildVoltBEFCycleTime,&BuildVoltBEFRemainTime,&BuildVoltBEFCurrPointTime);
		TempVoltBuildVoltBEF =CalADCVoltVirtualPhaseValue(BuildVoltBEFPoint,ADCDMA_ChannelNum,BuildVoltBEFDotNumber,BuildVoltBEFCycleTime,BuildVoltBEFRemainTime,BuildVoltBEFCurrPointTime);
		TempVoltBuildVoltBEF*=DefaultValHWCalibBuildVoltBEF;
		TempVoltBuildVoltAFT =CalADCVoltVirtualPhaseValue((int16_t *)(BuildVoltBEFPoint+(ADCDMAChannelOrd_BuildVoltAFT-ADCDMAChannelOrd_BuildVoltBEF)),ADCDMA_ChannelNum,BuildVoltBEFDotNumber,BuildVoltBEFCycleTime,BuildVoltBEFRemainTime,BuildVoltBEFCurrPointTime);
		TempVoltBuildVoltAFT*=DefaultValHWCalibBuildVoltAFT;
	}
	else
	{
		TempVoltBuildVoltBEF=0;
		TempVoltBuildVoltAFT=0;
	}


/****************************************************************************************************************************
 *                                                    标志位置位
 ****************************************************************************************************************************/
	ACTrace1stRecordFlag=DEF_TRUE;  //是否是第一次测算，0表示是，1表示不是，该配置会影响过零点检测

	ACdataStruction->InputType=ADCRecDataType_Null;   //数据使用完毕，清空当前消息片以供后续使用


/******************************************************************************************************************************
 *                                                    软件校准
 * ****************************************************************************************************************************/
	uint16_t tempCalibBuffer[SWCalibCoeffi_TOTNum];
	DataBase_ReadDataContent(Addr_CaliFactorCfg_GenPhaseVoltU, tempCalibBuffer, SWCalibCoeffi_TOTNum);
	TempVoltGensU *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseVoltL1]/10000;
	TempVoltGensV *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseVoltL2]/10000;
	TempVoltGensW *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseVoltL3]/10000;
	TempVoltGensUV *= (float)tempCalibBuffer[SWCalibCoeffi_GenLineVoltL12]/10000;
	TempVoltGensVW *= (float)tempCalibBuffer[SWCalibCoeffi_GenLineVoltL23]/10000;
	TempVoltGensWU *= (float)tempCalibBuffer[SWCalibCoeffi_GenLineVoltL31]/10000;
	TempVoltLoadU *= (float)tempCalibBuffer[SWCalibCoeffi_LoadPhaseVoltL1]/10000;
	TempVoltLoadV *= (float)tempCalibBuffer[SWCalibCoeffi_LoadPhaseVoltL2]/10000;
	TempVoltLoadW *= (float)tempCalibBuffer[SWCalibCoeffi_LoadPhaseVoltL3]/10000;
	TempVoltLoadUV *= (float)tempCalibBuffer[SWCalibCoeffi_LoadLineVoltL12]/10000;
	TempVoltLoadVW *= (float)tempCalibBuffer[SWCalibCoeffi_LoadLineVoltL23]/10000;
	TempVoltLoadWU *= (float)tempCalibBuffer[SWCalibCoeffi_LoadLineVoltL31]/10000;
	tempGenExciteVolt *= (float)tempCalibBuffer[SWCalibCoeffi_GenExciteVolt]/10000;
	tempGenExciteCurr *= (float)tempCalibBuffer[SWCalibCoeffi_GenExciteCurr]/10000;
	tempLoadExciteVolt *= (float)tempCalibBuffer[SWCalibCoeffi_LoadExciteVolt]/10000;
	tempLoadExciteCurr *= (float)tempCalibBuffer[SWCalibCoeffi_LoadExciteCurr]/10000;
	TempCurrGensU *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseCurrL1]/10000;
	TempCurrGensV *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseCurrL2]/10000;
	TempCurrGensW *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseCurrL3]/10000;
	TempVoltBuildVoltBEF *= (float)tempCalibBuffer[SWCalibCoeffi_BuildVoltBEF]/10000;
	TempVoltBuildVoltAFT *= (float)tempCalibBuffer[SWCalibCoeffi_BuildVoltAFT]/10000;
	TempPowerPGensU *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseVoltL1]/10000*tempCalibBuffer[SWCalibCoeffi_GenPhaseCurrL1]/10000;
	TempPowerPGensV *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseVoltL2]/10000*tempCalibBuffer[SWCalibCoeffi_GenPhaseCurrL2]/10000;
	TempPowerPGensW *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseVoltL3]/10000*tempCalibBuffer[SWCalibCoeffi_GenPhaseCurrL3]/10000;
	TempPowerQGensU *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseVoltL1]/10000*tempCalibBuffer[SWCalibCoeffi_GenPhaseCurrL1]/10000;
	TempPowerQGensV *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseVoltL2]/10000*tempCalibBuffer[SWCalibCoeffi_GenPhaseCurrL2]/10000;
	TempPowerQGensW *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseVoltL3]/10000*tempCalibBuffer[SWCalibCoeffi_GenPhaseCurrL3]/10000;
	TempPowerSGensU *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseVoltL1]/10000*tempCalibBuffer[SWCalibCoeffi_GenPhaseCurrL1]/10000;
	TempPowerSGensV *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseVoltL2]/10000*tempCalibBuffer[SWCalibCoeffi_GenPhaseCurrL2]/10000;
	TempPowerSGensW *= (float)tempCalibBuffer[SWCalibCoeffi_GenPhaseVoltL3]/10000*tempCalibBuffer[SWCalibCoeffi_GenPhaseCurrL3]/10000;

/****************************************************************************************************************************
 *                                                 		滤波
 ****************************************************************************************************************************/
	/* 功率数据滤波 */
	TempPowerPGensU = Comm_LowPass1OrderGetValue(TempPowerPGensU, &MemGenPowerP1, LowPassFilterValue_GenPower);
	TempPowerPGensV = Comm_LowPass1OrderGetValue(TempPowerPGensV, &MemGenPowerP2, LowPassFilterValue_GenPower);
	TempPowerPGensW = Comm_LowPass1OrderGetValue(TempPowerPGensW, &MemGenPowerP3, LowPassFilterValue_GenPower);
	TempPowerQGensU = Comm_LowPass1OrderGetValue(TempPowerQGensU, &MemGenPowerQ1, LowPassFilterValue_GenPower);
	TempPowerQGensV = Comm_LowPass1OrderGetValue(TempPowerQGensV, &MemGenPowerQ2, LowPassFilterValue_GenPower);
	TempPowerQGensW = Comm_LowPass1OrderGetValue(TempPowerQGensW, &MemGenPowerQ3, LowPassFilterValue_GenPower);
	TempPowerSGensU = Comm_LowPass1OrderGetValue(TempPowerSGensU, &MemGenPowerS1, LowPassFilterValue_GenPower);
	TempPowerSGensV = Comm_LowPass1OrderGetValue(TempPowerSGensV, &MemGenPowerS2, LowPassFilterValue_GenPower);
	TempPowerSGensW = Comm_LowPass1OrderGetValue(TempPowerSGensW, &MemGenPowerS3, LowPassFilterValue_GenPower);
	TempPFL1 = Comm_LowPass1OrderGetValue(TempPFL1, &MemGenPFL1, LowPassFilterValue_GenPower);
	TempPFL2 = Comm_LowPass1OrderGetValue(TempPFL2, &MemGenPFL2, LowPassFilterValue_GenPower);
	TempPFL3 = Comm_LowPass1OrderGetValue(TempPFL3, &MemGenPFL3, LowPassFilterValue_GenPower);

	/* 中值滤波 */
	// TempPowerPGensU = Comm_MediumFilterInputAndGetValue(&MemGenPowerP1, TempPowerPGensU);
	// TempPowerPGensV = Comm_MediumFilterInputAndGetValue(&MemGenPowerP2, TempPowerPGensV);
	// TempPowerPGensW = Comm_MediumFilterInputAndGetValue(&MemGenPowerP3, TempPowerPGensW);
	// TempPowerQGensU = Comm_MediumFilterInputAndGetValue(&MemGenPowerQ1, TempPowerQGensU);
	// TempPowerQGensV = Comm_MediumFilterInputAndGetValue(&MemGenPowerQ2, TempPowerQGensV);
	// TempPowerQGensW = Comm_MediumFilterInputAndGetValue(&MemGenPowerQ3, TempPowerQGensW);
	// TempPowerSGensU = Comm_MediumFilterInputAndGetValue(&MemGenPowerS1, TempPowerSGensU);
	// TempPowerSGensV = Comm_MediumFilterInputAndGetValue(&MemGenPowerS2, TempPowerSGensV);
	// TempPowerSGensW = Comm_MediumFilterInputAndGetValue(&MemGenPowerS3, TempPowerSGensW);

/******************************************************************************************************************************
 *                                                    变比率
 * ****************************************************************************************************************************/
	float tempTSFRatioBuffer[HWTransformRatio_TOTNum];
	DataBase_ReadDataContent(Addr_NominalCfg_TransfPrimaryVolt, (uint16_t *)tempTSFRatioBuffer, HWTransformRatio_TOTNum);
	float tempTSFRatioVolt = tempTSFRatioBuffer[HWTransformRatio_PrimaryVolt]/tempTSFRatioBuffer[HWTransformRatio_SecondaryVolt];
	float tempTSFRatioCurr = tempTSFRatioBuffer[HWTransformRatio_PrimaryCurr]/tempTSFRatioBuffer[HWTransformRatio_SecondaryCurr];
	
	TempVoltGensU *= tempTSFRatioVolt;
	TempVoltGensV *= tempTSFRatioVolt;
	TempVoltGensW *= tempTSFRatioVolt;
	TempVoltGensUV *= tempTSFRatioVolt;
	TempVoltGensVW *= tempTSFRatioVolt;
	TempVoltGensWU *= tempTSFRatioVolt;

	TempVoltLoadU *= tempTSFRatioVolt;
	TempVoltLoadV *= tempTSFRatioVolt;
	TempVoltLoadW *= tempTSFRatioVolt;
	TempVoltLoadUV *= tempTSFRatioVolt;
	TempVoltLoadVW *= tempTSFRatioVolt;
	TempVoltLoadWU *= tempTSFRatioVolt;

	TempCurrGensU *= tempTSFRatioCurr;
	TempCurrGensV *= tempTSFRatioCurr;
	TempCurrGensW *= tempTSFRatioCurr;
	TempPowerPGensU *= tempTSFRatioVolt*tempTSFRatioCurr;
	TempPowerPGensV *= tempTSFRatioVolt*tempTSFRatioCurr;
	TempPowerPGensW *= tempTSFRatioVolt*tempTSFRatioCurr;
	TempPowerQGensU *= tempTSFRatioVolt*tempTSFRatioCurr;
	TempPowerQGensV *= tempTSFRatioVolt*tempTSFRatioCurr;
	TempPowerQGensW *= tempTSFRatioVolt*tempTSFRatioCurr;
	TempPowerSGensU *= tempTSFRatioVolt*tempTSFRatioCurr;
	TempPowerSGensV *= tempTSFRatioVolt*tempTSFRatioCurr;
	TempPowerSGensW *= tempTSFRatioVolt*tempTSFRatioCurr;

/****************************************************************************************************************************
 *                                                    数据填装
 ****************************************************************************************************************************/
	FillGeneratorDataIntoRTMemory(&ACAD_RTGlobalData.GenVoltData, TempVoltGensU, TempVoltGensV, TempVoltGensW, TempVoltGensUV,
		TempVoltGensVW, TempVoltGensWU, TempFreGensU, TempFreGensV, TempFreGensW, GensUVPhaseOrder, GensUWPhaseOrder);
	FillGeneratorDataIntoRTMemory(&ACAD_RTGlobalData.LoadVoltData, TempVoltLoadU, TempVoltLoadV, TempVoltLoadW, TempVoltLoadUV,
		TempVoltLoadVW, TempVoltLoadWU, TempFreLoadU, TempFreLoadV, TempFreLoadW, LoadUVPhaseOrder, LoadUWPhaseOrder);
	FillExcitationDataIntoRTMemory(&ACAD_RTGlobalData.GenExcitationData, tempGenExciteVolt, tempGenExciteCurr);
	FillExcitationDataIntoRTMemory(&ACAD_RTGlobalData.LoadExcitationData, tempLoadExciteVolt, tempLoadExciteCurr);
	FillSynchronousDataIntoRTMemory(&ACAD_RTGlobalData.SyncData, TempSynchronousVoltU, TempSynchronousVoltV, TempSynchronousVoltW,
		TempSynchronousPhaseU, TempSynchronousPhaseV, TempSynchronousPhaseW, tempSyncErrU, tempSyncErrV, tempSyncErrW);
	FillPowerDataIntoRTMemory(&ACAD_RTGlobalData.PowerData, TempCurrGensU, TempCurrGensV, TempCurrGensW, TempPowerPGensU,
		TempPowerPGensV, TempPowerPGensW, TempPowerQGensU, TempPowerQGensV, TempPowerQGensW, TempPowerSGensU, TempPowerSGensV,
		TempPowerSGensW, TempPFL1, TempPFL2, TempPFL3);
	FillBuildVoltDataIntoRTMemory(&ACAD_RTGlobalData.BuildVoltData, TempFreBuildVoltBEF, TempVoltBuildVoltBEF, TempVoltBuildVoltAFT);

	// WriteDataBaseDataContent(FakeConfig_SyncPhaseDiffU, (uint16_t*)&TempSynchronousPhaseU, 2);
	// WriteDataBaseDataContent(FakeConfig_SyncPhaseDiffV, (uint16_t*)&TempSynchronousPhaseV, 2);
	// WriteDataBaseDataContent(FakeConfig_SyncPhaseDiffW, (uint16_t*)&TempSynchronousPhaseW, 2);
	// WriteDataBaseDataContent(FakeConfig_SyncVoltDiffU, (uint16_t*)&TempSynchronousVoltU, 2);
	// WriteDataBaseDataContent(FakeConfig_SyncVoltDiffV, (uint16_t*)&TempSynchronousVoltV, 2);
	// WriteDataBaseDataContent(FakeConfig_SyncVoltDiffW, (uint16_t*)&TempSynchronousVoltW, 2);
	// WriteDataBaseDataContent(FakeConfig_GenVoltU, (uint16_t*)&TempVoltGensU, 2);
	// WriteDataBaseDataContent(FakeConfig_GenVoltV, (uint16_t*)&TempVoltGensV, 2);
	// WriteDataBaseDataContent(FakeConfig_GenVoltW, (uint16_t*)&TempVoltGensW, 2);
	// WriteDataBaseDataContent(FakeConfig_LoadVoltU, (uint16_t*)&TempVoltLoadU, 2);
	// WriteDataBaseDataContent(FakeConfig_LoadVoltV, (uint16_t*)&TempVoltLoadV, 2);
	// WriteDataBaseDataContent(FakeConfig_LoadVoltW, (uint16_t*)&TempVoltLoadW, 2);
	// WriteDataBaseDataContent(FakeConfig_GenCurrU, (uint16_t*)&TempCurrGensU, 2);
	// WriteDataBaseDataContent(FakeConfig_GenCurrV, (uint16_t*)&TempCurrGensV, 2);
	// WriteDataBaseDataContent(FakeConfig_GenCurrW, (uint16_t*)&TempCurrGensW, 2);
	// WriteDataBaseDataContent(FakeConfig_GenActivePower, (uint16_t*)&TempPowerPGensU, 2);
	// WriteDataBaseDataContent(FakeConfig_GenReactivePower, (uint16_t*)&TempPowerQGensU, 2);
	// WriteDataBaseDataContent(FakeConfig_GenApparentPower, (uint16_t*)&TempPowerSGensU, 2);
	// WriteDataBaseDataContent(FakeConfig_GenPhaseOrdU2U1, (uint16_t*)&GensUVPhaseOrder, 2);
	// WriteDataBaseDataContent(FakeConfig_GenPhaseOrdU3U1, (uint16_t*)&GensUWPhaseOrder, 2);
	// WriteDataBaseDataContent(FakeConfig_GenFreqAverage, (uint16_t*)&ACAD_RTGlobalData.GenVoltData.GenFreqAverage, 2);
	// WriteDataBaseDataContent(FakeConfig_LoadFreqAverage, (uint16_t*)&ACAD_RTGlobalData.LoadVoltData.GenFreqAverage, 2);
	// WriteDataBaseDataContent(FakeConfig_GenPFAverage, (uint16_t*)&ACAD_RTGlobalData.PowerData.GenPFAverage, 2);

	if(CommPrintDataNum)
  	{
		CommData_PrintTotalQueue[CommData_GenFreqAverage         ] = ACAD_RTGlobalData.GenVoltData.GenFreqAverage;
		CommData_PrintTotalQueue[CommData_LoadFreqAverage        ] = ACAD_RTGlobalData.LoadVoltData.GenFreqAverage;
		CommData_PrintTotalQueue[CommData_GenPhaseVoltAverage    ] = ACAD_RTGlobalData.GenVoltData.GenPhaseVoltAverage;
		CommData_PrintTotalQueue[CommData_LoadPhaseVoltAverage   ] = ACAD_RTGlobalData.LoadVoltData.GenPhaseVoltAverage;
		CommData_PrintTotalQueue[CommData_GenCurrAverage         ] = ACAD_RTGlobalData.PowerData.GenCurrLAverage;
		CommData_PrintTotalQueue[CommData_GenActivePowerAverage  ] = ACAD_RTGlobalData.PowerData.GenPowerPTotal;
		CommData_PrintTotalQueue[CommData_GenReactivePowerAverage] = ACAD_RTGlobalData.PowerData.GenPowerQTotal;
		CommData_PrintTotalQueue[CommData_GenApparentPowerAverage] = ACAD_RTGlobalData.PowerData.GenPowerSTotal;
		CommData_PrintTotalQueue[CommData_GenPowerFactorAverage  ] = ACAD_RTGlobalData.PowerData.GenPFAverage;

		/* 组织数据 */
		CommPreparePrintData();
	}

#ifdef CalTime_Enable
 	GPIO_ResetBits(GPIOC, GPIO_PIN_13); //测试PID输出时机
#endif

	return DEF_TRUE;
}


/**
  * @brief  去直流函数
  * @param  none
  * @return none.
  */
static void Cal_PhaseFilter_Value(int16_t *StartAddr, int16_t *DCAddr, uint8_t AddrInterval, uint16_t Number)
{
	uint8_t i;

	/* 去直流 */
	int16_t *DataAddr=StartAddr;
	for (i = 0; i < Number; i++)
	{
		*DataAddr -= (int16_t)*DCAddr;
		DataAddr += AddrInterval;
		DCAddr += AddrInterval;
	}
}


//初始化或者复位全局测量数据
static void InitGlobalGensULastData(void)
{
	GensUGlobalVoltFre = 0;
}

static void InitGlobalGensVLastData(void)
{
	GensVGlobalVoltFre = 0;
}

static void InitGlobalGensWLastData(void)
{
	GensWGlobalVoltFre = 0;
}

// static void InitGlobalCurrULastData(void)
// {
// 	CurrUGlobalVoltFre = 0;
// }

// static void InitGlobalCurrVLastData(void)
// {
// 	CurrVGlobalVoltFre = 0;
// }

// static void InitGlobalCurrWLastData(void)
// {
// 	CurrWGlobalVoltFre = 0;
// }

static void InitGlobalLoadULastData(void)
{
	LoadUGlobalVoltFre = 0;
}

static void InitGlobalLoadVLastData(void)
{
	LoadVGlobalVoltFre = 0;
}

static void InitGlobalLoadWLastData(void)
{
	LoadWGlobalVoltFre = 0;
}

static void InitGlobalBuildVoltBEFLastData(void)
{
	BuildVoltBEFGlobalVoltFre = 0;
}


void FillGeneratorDataIntoRTMemory(ACAD_GeneratorDataTypeDef *GenSetData,float phaseVoltL1,float phaseVoltL2,float phaseVoltL3,
	float lineVoltL12,float lineVoltL23,float lineVoltL31,float freqL12,float freqL23,float freqL31,float phaseDiffU2U1,float phaseDiffU3U1)
{
	GenSetData->GenPhaseVoltL1 = phaseVoltL1;
	GenSetData->GenPhaseVoltL2 = phaseVoltL2;
	GenSetData->GenPhaseVoltL3 = phaseVoltL3;
	GenSetData->GenPhaseVoltAverage = (phaseVoltL1+phaseVoltL2+phaseVoltL3)/3;
	GenSetData->GenLineVoltL12 = lineVoltL12;
	GenSetData->GenLineVoltL23 = lineVoltL23;
	GenSetData->GenLineVoltL31 = lineVoltL31;
	GenSetData->GenLineVoltAverage = (lineVoltL12+lineVoltL23+lineVoltL31)/3;
	GenSetData->GenFreqL12 = freqL12;
	GenSetData->GenFreqL23 = freqL23;
	GenSetData->GenFreqL31 = freqL31;
	GenSetData->GenFreqAverage = (freqL12+freqL23+freqL31)/3;
	GenSetData->GenPhaseDiffU2U1 = phaseDiffU2U1;
	GenSetData->GenPhaseDiffU3U1 = phaseDiffU3U1;
}

void FillExcitationDataIntoRTMemory(ACAD_ExcitationDataTypeDef *ExcitationData,float excitationVolt,float excitationCurr)
{
	ExcitationData->ExcitationVolt = excitationVolt;
	ExcitationData->ExcitationCurr = excitationCurr;
	ExcitationData->ExcitationPower = excitationVolt*excitationCurr;
}

void FillSynchronousDataIntoRTMemory(ACAD_SynchronousDataTypeDef *SyncData,float voltDiffU1,float voltDiffU2,float voltDiffU3,
	float phaseDiffU1,float phaseDiffU2,float phaseDiffU3,float syncErrU1,float syncErrU2,float syncErrU3)
{
	SyncData->VoltDiffU1 = voltDiffU1;
	SyncData->VoltDiffU2 = voltDiffU2;
	SyncData->VoltDiffU3 = voltDiffU3;
	SyncData->VoltDiffAverage = (voltDiffU1+voltDiffU2+voltDiffU3)/3;
	SyncData->PhaseDiffU1 = phaseDiffU1;
	SyncData->PhaseDiffU2 = phaseDiffU2;
	SyncData->PhaseDiffU3 = phaseDiffU3;
	SyncData->PhaseDiffAverage = (phaseDiffU1+phaseDiffU2+phaseDiffU3)/3;
	SyncData->SyncErrU1 = syncErrU1;
	SyncData->SyncErrU2 = syncErrU2;
	SyncData->SyncErrU3 = syncErrU3;
	SyncData->SyncErrAverage = (syncErrU1+syncErrU2+syncErrU3)/3;
}


void FillPowerDataIntoRTMemory(ACAD_PowerDataTypeDef *PowerData,float currL1,float currL2,float currL3,float powerP1,float powerP2,
	float powerP3,float powerQ1,float powerQ2,float powerQ3,float powerS1,float powerS2,float powerS3,float PFL1,float PFL2,float PFL3)
{
	PowerData->GenCurrL1 = currL1;
	PowerData->GenCurrL2 = currL2;
	PowerData->GenCurrL3 = currL3;
	PowerData->GenCurrLAverage = (currL1+currL2+currL3)/3;
	PowerData->GenPowerP1 = powerP1;
	PowerData->GenPowerP2 = powerP2;
	PowerData->GenPowerP3 = powerP3;
	PowerData->GenPowerPTotal = powerP1+powerP2+powerP3;
	PowerData->GenPowerQ1 = powerQ1;
	PowerData->GenPowerQ2 = powerQ2;
	PowerData->GenPowerQ3 = powerQ3;
	PowerData->GenPowerQTotal = powerQ1+powerQ2+powerQ3;
	PowerData->GenPowerS1 = powerS1;
	PowerData->GenPowerS2 = powerS2;
	PowerData->GenPowerS3 = powerS3;
	PowerData->GenPowerSTotal = powerS1+powerS2+powerS3;
	PowerData->GenPFL1 = PFL1;
	PowerData->GenPFL2 = PFL2;
	PowerData->GenPFL3 = PFL3;
	PowerData->GenPFAverage = (PFL1+PFL2+PFL3)/3;
}

void FillBuildVoltDataIntoRTMemory(ACAD_BuildVoltDataTypeDef *BuildVoltData,float buildVoltFreq,float buildVoltBEF,float buildVoltAFT)
{
	BuildVoltData->BuildVoltFreq = buildVoltFreq;
	BuildVoltData->BuildVoltBEF = buildVoltBEF;
	BuildVoltData->BuildVoltAFT = buildVoltAFT;
}


void InitGovSyncErr()
{
	SyncErrU1stSta = DEF_FALSE;
	// SyncErrV1stSta = DEF_FALSE;
	// SyncErrW1stSta = DEF_FALSE;
	SyncErrModeLevelU = 0;
	// SyncErrModeLevelV = 0;
	// SyncErrModeLevelW = 0;
	SyncLastErrU = 0;
	// SyncLastErrV = 0;
	// SyncLastErrW = 0;
	PassPointMsgGensU.syncTraceIndex = PassPointMsgGensU.currentIndex;
	PassPointMsgGensV.syncTraceIndex = PassPointMsgGensV.currentIndex;
	PassPointMsgGensW.syncTraceIndex = PassPointMsgGensW.currentIndex;
	PassPointMsgLoadU.syncTraceIndex = PassPointMsgLoadU.currentIndex;
	PassPointMsgLoadV.syncTraceIndex = PassPointMsgLoadV.currentIndex;
	PassPointMsgLoadW.syncTraceIndex = PassPointMsgLoadW.currentIndex;
}



#endif /*	APP_MEASURE_GLOBALS	*/

/******************* (C) COPYRIGHT 2010 Feirui *****END OF FILE****/